package com.example.springbootdemo.aop;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@Slf4j
public class JDKProxyDemo {
  public static void main(String[] args) {
    Target target = new Target();
    ClassLoader loader = JDKProxyDemo.class.getClassLoader();
    Foo foo = (Foo) Proxy.newProxyInstance(loader, new Class[]{Foo.class}, (proxy, method, args1) -> {
      log.info("before ......");
      Object invoke = method.invoke(target, args);
      log.info("after ......");
      return invoke;
    });
    foo.foo();
  }
}
interface Foo{
  void foo();
}
@Slf4j
class Target implements Foo{

  @Override
  public void foo() {
    log.info("target foo");
  }
}
